﻿$(function () {
    toastr.options.positionClass = 'toast-bottom-center';
    toastr.options.time = 10000;
    // 自定义验证
    var checkMaxCount = (rule, value, callback) => {
        if (!value) {
            return callback(new Error('请填写最大检查人数'))
        }
        if (!Number.isInteger(Number(value))) {
            return callback(new Error('必须为整数'));
        }
        callback();
    };

    var vm = new Vue({
        el: '#app',
        components: {
           
        },
        computed: {
            
        },
        watch: {
           
        },
        data() {
            return {
                /*--搜索部分 --*/
                formLabelWidth: '100px',

                number: null,  // 查询输入框

                userData: {
                    name: null,            // 姓名
                    medicalCardNumber: null,// 就诊卡号
                    outPatientNumber: null,
                    inPatientNumber: null,
                    physicalExamNumber: null,
                    phoneNumber: null,
                    idCardNumber: null,
                    applyNumber: null,
                    medicalInsuranceNumber: null,
                    timeRange:null
                },

                selectedRows:[],  // 选中预约

                tableData:[], // 表格数据
            }
        },
        methods: {
            // 查询
            search() {
                var vm = this;
                let startTime = dayjs(vm.userData.timeRange[0]).format('YYYY-MM-DD HH:mm:ss');
                let endTime = dayjs(vm.userData.timeRange[1]).format('YYYY-MM-DD HH:mm:ss');
                vm.userData.timeRange = [startTime, endTime]
                abp.ajax({
                    type: 'post',
                    url: '/api/check-in/get-appointment-list',
                    data: JSON.stringify({
                        number: vm.number,
                        userData: vm.userData
                    })
                }).then(res => {
                    if (res.code === 0) {
                        vm.tableData = res.data;
                    }
                })
            },

            clearSearch() {
                var vm = this;
                Object.keys(vm.userData).forEach(key => {
                    if (key !== 'applyTimeRange') {
                        vm.userData[key] = null;
                    }
                });
                vm.number = null;
            },
            // 单个预约签到
            singleCheckIn(appointNumber) {
                var vm = this;
                abp.message.confirm('将对当前预约进行签到')
                    .then(confirmed => {
                        if (confirmed) {
                            abp.ajax({
                                type: 'get',
                                url: `/api/check-in/check-in?appointNumber=${appointNumber}`,
                            }).then(res => {
                                if (res.data.succeed) {
                                    abp.notify.success("签到成功，正在打印排队小票....");
                                    vm.search();
                                    // 此处开始打印队列小票的逻辑
                                    vm.print();
                                } else {
                                    abp.message.error(res.data.error)
                                }
                            })
                        }
                    })
            },

            // 打印队列小票
            print() {
                const vm = this;
                debugger;
            },

            // 重新打印队列小票
            reprint() {
                const vm = this;
                debugger;
            },

            selectionChange(rows) {
                var vm = this;
                vm.selectedRows = rows;
            },

            getSelectable(row, index) {
                return row.status===1
            },

            // 页面初始化
            init() {
                var vm = this;
                var begin = new Date((new Date()).setHours(0, 0, 0, 0));
                var end = new Date((new Date()).setHours(23, 59, 59, 999));
                vm.userData.timeRange = [begin, end];
            }
        },
        created() {
            this.init();
        }
    });
});